package com.ruoyi.web.controller.production.blade;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.production.domain.blade.BladeApply;
import com.ruoyi.production.service.blade.IBladeApplyService;
import io.netty.util.internal.UnstableApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 刀片申请Controller
 *
 * @author ruoyi
 * @date 2021-07-11
 */
@RestController
@RequestMapping("/blade/apply")
@Api(value = "刀片申请",tags = "刀片申请相关API")
public class BladeApplyController extends BaseController
{
    @Autowired
    private IBladeApplyService bladeApplyService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询刀片申请列表
     */
    @PreAuthorize("@ss.hasPermi('blade:apply:list')")
    @GetMapping("/list")
    @ApiOperation("获取刀片申请列表")
    @ApiImplicitParam(name = "bladeApply", value = "刀片申请实体", paramType = "body", dataType = "BladeApply")
    public TableDataInfo list(BladeApply bladeApply)
    {
        startPage();
        List<BladeApply> list = bladeApplyService.selectBladeApplyList(bladeApply);
        return getDataTable(list);
    }

    /**
     * 导出刀片申请列表
     */
    @PreAuthorize("@ss.hasPermi('blade:apply:export')")
    @Log(title = "刀片申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出刀片申请数据")
    @ApiImplicitParam(name = "bladeApply", value = "刀片申请实体", paramType = "body", dataType = "BladeApply")
    public AjaxResult export(BladeApply bladeApply)
    {
        List<BladeApply> list = bladeApplyService.selectBladeApplyList(bladeApply);
        ExcelUtil<BladeApply> util = new ExcelUtil<BladeApply>(BladeApply.class);
        return util.exportExcel(list, "刀片申请数据");
    }

    /**
     * 获取刀片申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('blade:apply:query')")
    @GetMapping(value = "/{bladeApplyId}")
    @ApiOperation("获取刀片申请详细信息")
    @ApiImplicitParam(name = "bladeApplyId", value = "刀片申请主键", paramType = "path", dataType = "Long")
    public AjaxResult getInfo(@PathVariable("bladeApplyId") Long bladeApplyId)
    {
        return AjaxResult.success(bladeApplyService.selectBladeApplyById(bladeApplyId));
    }

    /**
     * 新增刀片申请
     */
    @PreAuthorize("@ss.hasPermi('blade:apply:add')")
    @Log(title = "刀片申请", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增刀片申请信息")
    @ApiImplicitParam(name = "bladeApply", value = "刀片申请实体类", paramType = "body", dataType = "BladeApply")
    public AjaxResult add(@RequestBody BladeApply bladeApply)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        bladeApply.setUserId(loginUser.getUser().getUserId());
        return toAjax(bladeApplyService.insertBladeApply(bladeApply));
    }

    /**
     * 修改刀片申请
     */
    @PreAuthorize("@ss.hasPermi('blade:apply:edit')")
    @Log(title = "刀片申请", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改刀片申请信息")
    @ApiImplicitParam(name = "bladeApply", value = "刀片申请实体类", paramType = "body", dataType = "BladeApply")
    public AjaxResult edit(@RequestBody BladeApply bladeApply)
    {
        return toAjax(bladeApplyService.updateBladeApply(bladeApply));
    }

    /**
     * 删除刀片申请
     */
    @PreAuthorize("@ss.hasPermi('blade:apply:remove')")
    @Log(title = "刀片申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bladeApplyIds}")
    @ApiOperation("删除刀片申请信息")
    @ApiImplicitParam(name = "bladeApplyIds", value = "刀片申请主键数组", paramType = "path", dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] bladeApplyIds)
    {
        return toAjax(bladeApplyService.deleteBladeApplyByIds(bladeApplyIds));
    }
}
